<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/17 0017
  Time: 上午 10:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/common.css">
</head>
<body>

    <div class="box-padding-15">
         <span class="layui-breadcrumb">
          <a href="#">首页</a>
          <a href="javascript:;">用户管理</a>
          <a><cite>修改密码</cite></a>
        </span>
        <hr>
        <div class="box-form">
            <form class="layui-form " action="/password" method="post">
                <input type="hidden" name="id" value="${account.uId}">
                <input type="hidden" name="userPwd" value="${account.userPwd}">
                <div class="layui-form-item">
                    <label class="layui-form-label">原密码：</label>
                    <div class="layui-input-block">
                        <input type="password" name="oldPassword" required  lay-verify="required|pass" autocomplete="off" class="layui-input">
                    </div>   <%--input框里name里写实体里相应的字段--%>
                </div>

                <div id="passDiv" class="layui-form-item ">
                    <label class="layui-form-label">新密码：</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" autocomplete="off" class="layui-input" lay-verify="required|pass">
                    </div>
                </div>

                <div id="phoneDiv" class="layui-form-item ">
                    <label class="layui-form-label">确认密码：</label>
                    <div class="layui-input-block">
                        <input type="password" name="con_pass"   autocomplete="off" class="layui-input" lay-verify="required|pass">
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formSubmit">保存</button>
                        <a href="/" target="_top"><button type="button" class="layui-btn layui-btn-primary">取消</button></a>
                    </div>
                </div>
            </form>
        </div>

    </div>


<script src="/static/plugins/jquery-3.2.1.min.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script src="/static/js/common.js"></script>
<script>

    layui.use(['element','layer','form'], function() {
        var form = layui.form;
        var layer = layui.layer;

        form.verify({
            pass: [
                /^[\S]{5,12}$/
                ,'密码必须5到12位，且不能出现空格'
            ]
        })
        form.on('submit(formSubmit)',function(data){

            var field = data.field;
            if(field.password!=field.con_pass){
                layer.msg("两次输入密码不一致",{icon:2,time:1500});
                return false;
            }
            $.ajax({
                url:"/passwordChange",
                type:'post',
                dataType:'json',
                data:{password:field.password,oldPassword:field.oldPassword},
                success:function(msg){
                    if(msg.code==1){
                        parent.layui.layer.msg("修改成功，请重新登陆",{time:2000},function(){
                            parent.location.href="/login";
                        })
                    }else{
                        layer.msg(msg.message,{icon:2,time:1500})
                    }
                },
                error:function () {

                }
            })
            return false;
        })
    })


</script>
</body>
</html>
